﻿using System;
using System.Collections.Generic;
using System.Text;
using System.IO.Packaging;

namespace OPCDiffCore
{
    /// <summary>
    /// Some util methods.
    /// </summary>
    internal class Utils
    {
        /// <summary>
        /// Check if the specified part is a text based part.
        /// </summary>
        /// <param name="part">The part to check.</param>
        /// <returns><b>true</b> if the specified part is a text based part, else <b>false</b>.</returns>
        internal static bool IsTextPart(PackagePart part)
        {
            return part.ContentType.ToString().EndsWith("text");
        }

        /// <summary>
        /// Check if the specified part is an XML based part.
        /// </summary>
        /// <param name="part">The part to check.</param>
        /// <returns><b>true</b> if the specified part is an XML based part, else <b>false</b>.</returns>
        internal static bool IsXmlPart(PackagePart part)
        {
            return part.ContentType.ToString().EndsWith("xml") && !IsRelationshipPart(part);
        }

        /// <summary>
        /// Check if the specified part is a relationship part.
        /// </summary>
        /// <param name="part">The part to check.</param>
        /// <returns><b>true</b> if the specified part is a relationship part, else <b>false</b>.</returns>
        internal static bool IsRelationshipPart(PackagePart part)
        {
            return part.ContentType.ToString().EndsWith("relationships+xml");
        }

        /// <summary>
        /// Check if the specified part is a binary based part. Actually it uses the inverse result of a call
        /// to the 'IsTextPart' method.
        /// </summary>
        /// <param name="part">The part to check.</param>
        /// <returns><b>true</b> if the specified part is a binary based part, else <b>false</b>.</returns>
        internal static bool IsBinaryPart(PackagePart part)
        {
            return !IsTextPart(part) && !IsXmlPart(part) && !IsRelationshipPart(part);
        }

        /// <summary>
        /// Check if the specified object 
        /// </summary>
        /// <param name="obj">The object to check.</param>
        /// <returns>True if the object is not null, else false.</returns>
        internal static bool HasValue(object obj)
        {
            return obj != null;
        }
    }
}
